package com.huike.web.controller.report;


import com.huike.common.utils.SecurityUtils;
import com.huike.report.domain.vo.IndexTodayInfoVO;
import com.huike.report.domain.vo.IndexTodoInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutionException;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;


    /**
     * 首页--基础数据统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime) {
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime, endCreateTime));
    }

    /**
     * 首页今日简报信息
     * 根据当前用户  与 当前时间查询
     *
     * @return
     */
    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo() throws ExecutionException, InterruptedException {
        //获取当前时间
        Date date = new Date();
        String today = new SimpleDateFormat("yyyy-MM-dd").format(date);

        //获取当前用户
        String username = SecurityUtils.getUsername();

        //将当前用户与当前时间传递过去
        IndexTodayInfoVO indexTodayInfoVO = reportService.getTodayInfo(username, today);
        return AjaxResult.success("操作成功",indexTodayInfoVO);
    }

    /**
     * 首页 —— 待办数据统计接口
     * 获取当前用户的待办数据
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(String beginCreateTime, String endCreateTime) throws ExecutionException, InterruptedException {
        //获取当前用户
        String username = SecurityUtils.getUsername();

        IndexTodoInfoVO indexTodoInfoVO = reportService.getToDoInfo(username, beginCreateTime, endCreateTime);
        return AjaxResult.success("操作成功",indexTodoInfoVO);
    }
}